Repository navigation
Add client options, WARN/TRACE/FATAL log levels and enum parsers - #48
Open
DzmitryHumianiuk wants to merge 1 commit into
Open
DzmitryHumianiuk wants to merge 1 commit into
DzmitryHumianiuk wants to merge 1 commit into
Conversation
NewClient and NewReportingClient take variadic options after the authentication option. WithResponseMiddleware adds a hook that is called with every response and its body before the client's own error handling; hooks are chained and the first error stops the chain. The same hook serves the Resty-based methods and the generated client. ParseLaunchMode, ParseItemType and ParseStatus convert user input to the typed values. Part of #27 Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This was referenced Nov 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Part of #27 (slice L1). No dependencies.
feat/http-retries(L4) andfeat/config-loader(L5) are stacked on this branch.NewClientandNewReportingClientget a variadicopts ...Option, so that later settings (retries in L4, batching in L3) don't need new constructors. This changes the constructor signatures, which is why it should land before the first v6 tag (#32).Changes
pkg/gorp/options.go(new):Option,ResponseMiddleware,WithResponseMiddleware.func(resp *http.Response, body []byte) error, the shape ofopenapi.ResponseMiddlewareFunction. One function serves the Resty-based methods and the generated client.ResponseMiddlewareslot.configureOpenAPIputs the user's middlewares in front of whatever the configuration already has there, it never replaces it.pkg/gorp/client.go,pkg/gorp/reporting_client.go:opts ...Optionon both constructors.pkg/gorp/model_api.go:LogLevelTrace,LogLevelWarn,LogLevelFatalnext to the existingDEBUG/INFO/ERROR.pkg/gorp/model_parse.go(new):ParseLaunchMode,ParseItemType,ParseStatus. They ignore case and surrounding spaces and return an error wrappingErrUnknownValuethat lists the accepted values.Only one option is added here on purpose.
WithRetrycomes with L4. I did not add request middlewares, a user agent or a timeout option, because nothing in #26/#27 needs them yet.Behaviour change
Source compatible for ordinary calls:
NewClient(u, auth)andNewReportingClient(host, project, auth)compile unchanged.Not compatible for code that stores a constructor in a typed function variable or passes it as a function value. Checked with a probe file:
Without options nothing changes on the wire or in the errors.
With a response middleware, the Resty clients buffer response bodies (
SetResponseBodyUnlimitedReads(true)), otherwise the middleware would get an empty body for a response that Resty decoded into a result.Fit with #36 (
fix/api-errors)I read
pkg/gorp/errors.goonorigin/fix/api-errors; this PR does not depend on it. #36 assignsconf.ResponseMiddleware = OpenAPIErrorMiddlewareinnewAPIClient, the same place where this PR callso.configureOpenAPI(conf), so the two conflict inpkg/gorp/client.go(and, for L4, inAGENTS.md).Resolution: keep both lines, #36's first:
The other order would silently drop the user's middlewares on the generated client. I did a trial merge of
feat/http-retries(which contains this PR) withorigin/fix/api-errors, resolved it this way, andgo build ./... && go vet ./... && go test -race ./...passed. The Resty side needs nothing: both branches keep the namedefaultHTTPErrorHandler.Verification
On
feat/client-options(cfb8ad0):go build ./... && go vet ./...: okgo test -race ./...: ok (internal/commands,pkg/gorp)go run github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.15.0 run ./...: 0 issuesTests (
pkg/gorp/options_test.go,pkg/gorp/model_parse_test.go):StartLaunchstill decodesid;*HTTPError(Resty) or*openapi.GenericOpenAPIError(generated) with the body intact;ResponseMiddlewareof the generated configuration is kept and runs after the user's.Investigation log
ClientOptionalready exists inpkg/gorp/client.goasfunc() *http.Client(the authentication builder), so the new type is namedOption.cfg.ResponseMiddlewarefor every response, before its own status check:pkg/openapi/api_launch.go:120-125. There is one slot (pkg/openapi/configuration.go:98).go.mod:11) runs every response middleware even after one failed and only collects the errors (client.go:2568-2573in the module cache). So the user's middlewares anddefaultHTTPErrorHandlerare registered as one Resty middleware; otherwise "the first error wins" would not hold.Response.Bytes()is empty after auto-unmarshal unless unlimited reads are on (response.go:142-151), hence the buffering.LogLevelenum hasERROR, WARN, INFO, DEBUG, TRACE, FATAL, UNKNOWNand matches names ignoring case: service-apiinfrastructure/persistence/entity/enums/LogLevel.java:28-32,60-65(develop, 017642e9).TestItemTypeEnum.java:25-39, statuses fromStatusEnum.java:25-35(IN_PROGRESSandTO_RUNare not for clients, soParseStatusrejects them), modes fromreporting/Mode.java:27. The values already inmodel_enums.gomatch.Not verified
🤖 Generated with Claude Code